package top.alanshelby.exception;

import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class CustomExceptionResolver implements HandlerExceptionResolver {
    @Override
    public ModelAndView resolveException(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) {
        String message;
        // 异常处理逻辑
        if (e instanceof CustomException) {
            message = ((CustomException) e).getMsg();
        } else {
            message = "未知错误";
        }
        ModelAndView mv = new ModelAndView();
        mv.addObject("message", message);
        mv.setViewName("exception/custom");
        return mv;
    }
}
